package service;


import com.google.gson.Gson;
import com.google.gson.JsonObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;



@WebServlet(urlPatterns = {"/merch"})
public class merchService extends HttpServlet {
    public boolean c2dictionary;
    public merch data;

    public merchService() {
        super();
        // TODO Auto-generated constructor stub
        this.c2dictionary = true;
        this.data = new merch();
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html; charset=utf-8");
        PrintWriter out = response.getWriter();
        try {
            response.setHeader("Cache-Control", "no-store");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Access-Control-Allow-Origin", "*");
            response.setDateHeader("Expires", 0);
            Gson gsres = new Gson();
            String res = gsres.toJson(new merchService());
            out = response.getWriter();
            out.println(res);
        } catch (Exception e) {
            out.print("error: data");
            e.printStackTrace();
        }

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}